﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;

namespace FBGraph.ClientGenerator.CodeGen
{
    public class ImportsList : List<String>, ICodeGenObject
    {
        public ImportsList(params String[] imports) : base(imports) { }

        public void Write(CodeGenWriter writer)
        {
            var orderedImports =
                from import in this
                orderby
                    import.StartsWith("System") descending,
                    import.StartsWith("Newtonsoft") descending,
                    import
                select import;

            foreach (var import in orderedImports)
            {
                writer.WriteLine("using {0};", import);
            }
        }

        public void Suggest(String import)
        {
            if (!this.Contains(import)) this.Add(import);
        }
    }
}